﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Demo
{
    public class LuaBehaviour : MonoBehaviour
    {
        public string scriptName;
        protected void Awake()
        {
            if (string.IsNullOrEmpty(scriptName))
                scriptName = name;
            CallMethod(scriptName, "Awake", gameObject);
        }

        protected void Start()
        {
            CallMethod(scriptName, "Start");
        }

        protected void OnDestroy()
        {
            CallMethod(scriptName, "OnDestroy");
        }


        public static object[] CallMethod(string module, string func, params object[] args)
        {
            LuaManager luaMgr = LuaManager.Instance;
            if (luaMgr == null) return null;
            return luaMgr.CallFunction(module + "." + func, args);
        }
    }
}
